package java3_14;

/**
 *
 4：公司有公司名称，注册地址，电话，经营范围等属性，公司有很多员工（暂用String数组表示），
 *公司有招聘员工方法，有输出员工信息方法，以及辞退员工方法(*选做)。
 *用oo的思想模拟
 */
public class Company {
    String name;
    String address;
    String phoneNumber;
    String range;
    String [] employee = new String[10];

    public void add(String newName){
        for (int i = 0; i < employee.length; i++) {
            if (employee[i]==null){
                employee[i] = newName;
                return;
            }
            if (employee[i]!=null){
                if (employee[i].equals(newName)){
                    System.out.println("添加的员工信息有重复！添加失败！");
                }
            }
        }
    }

    public void print(){
        for (int i = 0; i < employee.length; i++) {
            if (employee[i]==null){
                System.out.println();
                break;
            }
            System.out.print(employee[i]+" ");
        }
    }
    public void dismiss(String name){
        for (int i = 0; i < employee.length; i++) {
            if (employee[i]==null){
                System.out.println("您要辞退的员工不存在！");
                return;
            }
            if (employee[i].equals(name)){
                for (int j = i+1; j < employee.length; j++) {
                    employee[j-1] = employee[j];
                    if (employee[j]==null){
                        return;
                    }
                }
            }
        }
    }
}
